package test;

import core.*;
import fileoperation.FileDeletion;
import gitobject.Index;
import repository.Repository;

import java.io.File;
import java.io.IOException;

public class test1 {

    public static void main(String[] args) throws Exception {

        try {
            String path = "/home/zsq/code/test";
            Repository repository = new Repository(path);
            repository.createRepo();
            JitInit.init(path);

            File file1 = new File(path + File.separator + "1.txt");
            File file2 = new File(path + File.separator + "2.txt");
            File file3 = new File(path + File.separator + "3.txt");


            JitAdd.add(file1);
            Index index = Index.deserialize(new File(Repository.getGitDir() + File.separator + "index"));
            System.out.println("index = " + index.fileOb.size());

            JitAdd.add(file2);
            index = Index.deserialize(new File(Repository.getGitDir() + File.separator + "index"));
            System.out.println("index = " + index.fileOb.size());
            JitStatus.status(path);

            JitAdd.add(file1);
            index = Index.deserialize(new File(Repository.getGitDir() + File.separator + "index"));
            System.out.println("index = " + index.fileOb.size());
            JitStatus.status(path);

            JitRm.remove(file2);
            index = Index.deserialize(new File(Repository.getGitDir() + File.separator + "index"));
            System.out.println("index = " + index.fileOb.size());
            JitStatus.status(path);

            JitCommit.commit("First");
//            index = Index.deserialize(new File(Repository.getGitDir() + File.separator + "index"));
//            System.out.println("index = " + index.fileOb.size());
            System.out.println("\n");

            System.out.println("-----------");

            JitAdd.add(file2);
            JitCommit.commit("Second");
            System.out.println("\n");
            JitLog.log();
            JitStatus.status(path);
            JitReset.mixed("0e8a068e45b9f37b9f3d64115bd0473bc9d61fbb");
            JitStatus.status(path);
            JitLog.log();

            JitBranch.branch("newBranch");
            JitBranch.branch("");
            System.out.println("---------");

            JitCheckout.checkout("master");
            JitBranch.branch("");
            System.out.println("---------");

            JitBranch.deleteBranch("master");
            JitBranch.deleteBranch("newBranch");
            JitBranch.branch("");
            System.out.println("---------");

            JitLog.log();
        } catch (Exception e){
            e.printStackTrace();
        }
    }
}